package com.example.PolimiAssistant.common;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import com.example.PolimiAssistant.R;

/**
 * DialogHandler.java
 *
 * This class is used as a dialog manager, that offer the services of displaying
 * different dialogs requiring only the dialog text and the actions that have to
 * be performed given the user answers or no action at all.
 *
 * This class is used to display a message in which the user is given a choice
 * through and alert message. The user can customize the message using the
 * constructor method.
 */
public class DialogHandler {


    private Runnable yesProcedure = null;
    private Runnable noProcedure = null;




    public void confirmDialog(Activity activity, String title, String message,
                           String yesMessage, String noMessage,
                           Runnable yesProc, Runnable noProc) {

        yesProcedure = yesProc;
        noProcedure = noProc;

        AlertDialog dialog;
        dialog = new AlertDialog.Builder(activity).create();

        dialog.setTitle(title);
        dialog.setMessage(message);
        dialog.setCancelable(false);

        dialog.setButton(DialogInterface.BUTTON_POSITIVE, yesMessage,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int buttonId) {
                        yesProcedure.run();
                    }
                });
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, noMessage,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int buttonId) {
                        noProcedure.run();
                    }
                });

        dialog.show();
    }

}
